package ru.st.selenium.applogic2;

import java.util.List;

import org.openqa.selenium.WebElement;

import ru.st.selenium.applogic.FilmHelper;
import ru.st.selenium.model.Film;
import ru.st.selenium.pages.EditFilmPage;
import ru.st.selenium.pages.InternalPage;


public class FilmHelper2 extends DriverBasedHelper implements FilmHelper {

  


public FilmHelper2(ApplicationManager2 manager) {
    super(manager.getWebDriver());
  }

  @Override
  public void create(Film film) {
    pages.addNewFilmPage.ensurePageLoaded()
    	.setNameFilmField(film.getTitle())
    	.setNotesForFilmField(film.getNotes())
    	.setYearFilmField(film.getYear())
    	.clickSubmitButton();

  }

  
  public void delete() {
    pages.editFilmPage.ensurePageLoaded()
    .clickDeleteButton();

  }

  @Override
  public List<Film> search(String title) {
    // TODO Auto-generated method stub
    return null;
  }

@Override
public boolean isNewFilmAdded(Film film) {
			return isFilmAdded() &&
				pages.editFilmPage.getTitleFilm().startsWith(film.getTitle());
}
@Override
public boolean isFilmAdded() {
		return pages.editFilmPage.waitPageLoaded();
}

@Override
public boolean isNewFilmNotAdded() {
	
	return pages.addNewFilmPage.waitPageLoaded();
}

@Override
public boolean chooseAnyFilm(int n) {
	pages.internalPage.clickRndFilm(n);
	return pages.editFilmPage.waitPageLoaded();
	
}

@Override
public void chooseAndDeleteAnyFilm(int n) {
	chooseAnyFilm(n);
	delete();
	
}

@Override
public int getNumberOfFilms() {
			return pages.internalPage.numberOfFilms();
	
}


@Override
public boolean isNumberOfFilmsLess(int number) {
	int numberAfterDelete = pages.internalPage.numberOfFilms();
		if (numberAfterDelete==number-1)
	return true;
	else 
		return false;
}

@Override
public String findFilmWithName(String name) throws InterruptedException   {
	
	return pages.internalPage.resultOfSearchFilm(name);
	
}



}
